﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DoctorManagement.Core;

namespace Doctor.Data
{
    public class PatientManagementRepository
    {
        public List<Patient> GetAllPatients()
        {
            using (DoctorDataContext ddc = new DoctorDataContext())
            {
                return (from p in ddc.tblPatients
                        join f in ddc.tblFamilies
                        on p.FamilyId equals f.Id
                        //join fl in ddc.tblFileManagements
                        //on p.Id equals fl.PatientId
                        //join fl in ddc.tblFileManagements
                        //on p.Id equals fl.PatientId
                        where p.IsDeleted.Equals(false)
                        select new Patient
                        {
                            Id = p.Id,
                            RegistrationNo = p.RegistrationNo,
                            RegistrationDate = p.RegistrationDate,
                            FamilyRegistrationId = f.FamilyRegistrationId,
                            FamilyId = f.Id,
                            FullName = p.FirstName + " " + p.MiddleName + " " + p.LastName,
                            Mobile1 = p.Mobile1,
                            Occupation = p.Occupation,
                            Email = p.Email,
                            DOB = p.DOB.GetValueOrDefault(),
                            DoctorName = ""
                        }).ToList();
            }
        }

        public int GetTopPatientId()
        {
            using (DoctorDataContext ddc = new DoctorDataContext())
            {
                return (from p in ddc.tblPatients
                        orderby p.Id descending 
                        select  p.Id + 1).FirstOrDefault();
            }
        }
    }
}
